DeepAgent module
DeepAgent
Bases: Module
A coding agent whose tools are a sandboxed copy of a workdir.
DeepAgent is a thin specialization of FunctionCallingAgent
that mounts the workdir in a MontySandbox and exposes the
sandbox's tool methods to the LM:
read_file: read a file by 1-based line range (paginated).list_files: list files matching a glob.search_files: glob for files and grep their contents (regex).write_file: create/overwrite a file.edit_file: exact-string replacement.run_python_code: run a Python snippet directly in the sandbox.run_python_file: run a self-contained script the agent wrote into the overlay.
Every tool is backed by the sandbox's copy-on-write overlay and the
Monty interpreter, so the agent is host-safe by construction:
reads fall through to the real workdir but writes, edits and code
execution can never modify it or reach the host — so there is nothing
to gate, and all tools are always available. Inspect what the agent
did through agent.sandbox — changes(), journal(),
read_overlay() — and persist any of it yourself if desired.
The constructor mirrors FunctionCallingAgent — every
parameter on that class is accepted here with identical semantics.
The additions are workdir (required) and the sandbox timeout.
User-supplied tools are appended to the built-in ones.
Example:
import synalinks
import asyncio
async def main():
lm = synalinks.LanguageModel(model="ollama/mistral")
inputs = synalinks.Input(data_model=synalinks.ChatMessages)
outputs = await synalinks.DeepAgent(
workdir="/tmp/my_project",
language_model=lm,
)(inputs)
agent = synalinks.Program(inputs=inputs, outputs=outputs)
messages = synalinks.ChatMessages(messages=[
synalinks.ChatMessage(
role="user",
content="What's in this directory?",
)
])
result = await agent(messages)
print(result.get("messages")[-1].get("content"))
asyncio.run(main())
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workdir
|
str
|
Optional working directory the agent operates on. When given it must exist and is mounted read-through in the sandbox (the LM's writes/edits stay in the overlay and never touch it). When omitted, the sandbox starts as an empty in-memory filesystem. |
None
|
timeout
|
float
|
Per-snippet execution budget in seconds for
|
30.0
|
tools
|
list
|
Additional |
None
|
sandbox
|
Sandbox
|
Optional ready-made sandbox to operate on instead
of building one from |
None
|
max_subagent_depth
|
int
|
When Subagent forks here are filesystem branches (each gets a
fresh interpreter), so across parallel subagents you can fold
back all their file changes. Folding back Python REPL state
(variables/functions/imports) across subagents is a
|
0
|
schema
|
dict
|
JSON schema for the final answer. |
None
|
data_model
|
DataModel
|
DataModel for the final answer.
Mutually exclusive with |
None
|
language_model
|
LanguageModel
|
The language model that drives the agent loop. |
None
|
prompt_template
|
str
|
Forwarded to the tool-call generator. |
None
|
examples
|
list
|
Few-shot examples for the tool-call generator. |
None
|
instructions
|
str
|
Override the default system instructions. When omitted, the default is built from the workdir. |
None
|
final_instructions
|
str
|
Instructions for the final-answer
generator. Defaults to |
None
|
temperature
|
float
|
LM sampling temperature. Defaults to 0.0. |
0.0
|
use_inputs_schema
|
bool
|
Include the input schema in the prompt. |
False
|
use_outputs_schema
|
bool
|
Include the output schema in the prompt. |
False
|
reasoning_effort
|
str
|
Forwarded to the generators (for reasoning-capable LMs). |
None
|
use_chain_of_thought
|
bool
|
When |
False
|
autonomous
|
bool
|
When |
True
|
return_inputs_with_trajectory
|
bool
|
When |
True
|
max_iterations
|
int
|
Maximum number of tool-call rounds. Defaults to 10 (coding tasks tend to need more rounds than RAG / SQL). |
10
|
streaming
|
bool
|
Stream the final answer when no |
False
|
name
|
str
|
Module name. |
None
|
description
|
str
|
Module description. |
None
|
Source code in synalinks/src/modules/agents/deep_agent.py
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 | |
discard_subagent(handle)
async
Drop a subagent's branch without applying any of its changes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
handle
|
str
|
A handle returned by |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
|
Source code in synalinks/src/modules/agents/deep_agent.py
merge_subagent(handle, paths=None, force=False)
async
Apply a subagent's filesystem changes onto your own filesystem.
Folds the writes and deletions a subagent made on its branch into
your filesystem. The handle stays valid afterwards, so you can merge
a different subset later. A path you also changed since spawning is a
conflict: it is refused (reported under conflicts /
skipped and left as-is) unless you pass force=True, which
applies the subagent's version (last writer wins).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
handle
|
str
|
A handle returned by |
required |
paths
|
list
|
Optional subset of virtual paths to merge; omit to merge all of the subagent's changes. |
None
|
force
|
bool
|
Apply conflicting paths instead of refusing them. Defaults to false. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
|
dict
|
|
Source code in synalinks/src/modules/agents/deep_agent.py
spawn_subagents(tasks)
async
Run subagents in parallel, each on an isolated branch of the filesystem.
Each task is handed to a fresh subagent working on its own
copy-on-write fork of the current filesystem: it can read every
file you see now and freely write, edit or delete, but its changes
are isolated and do NOT affect your filesystem. Subagents run
concurrently. Nothing is applied automatically — review each
returned diff and then call merge_subagent(handle) to fold
the changes you want into your filesystem (or
discard_subagent(handle) to drop a branch).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tasks
|
list
|
One instruction string per subagent describing what that subagent should accomplish. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
|
dict
|
( |
|
dict
|
changes), or |
|
dict
|
failed; plus a top-level |
Source code in synalinks/src/modules/agents/deep_agent.py
468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 | |
get_default_instructions(workdir)
Default system instructions for the deep agent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workdir
|
Optional[str]
|
Absolute path of the agent's working directory, or
|
required |
Returns:
| Type | Description |
|---|---|
str
|
A prompt string describing the tool plan. |
Source code in synalinks/src/modules/agents/deep_agent.py
get_subagent_instructions()
System instructions for a spawned subagent (depth >= 1).
Source code in synalinks/src/modules/agents/deep_agent.py
get_subagent_tools_guidance()
Guidance appended to the instructions when subagents are enabled.